home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Inne
/
Gry
/
Carnage_Contest
/
scripts
/
CC Original
/
weapons
/
Bazooka.lua
< prev
next >
Wrap
Text File
|
2010-08-31
|
6KB
|
154 lines
--------------------------------------------------------------------------------
-- Weapon Bazooka + Projectile Rocket
-- Original Carnage Contest Weapon
-- Script by DC, August 2009, www.UnrealSoftware.de
--------------------------------------------------------------------------------
-- Setup Tables
if cc==nil then cc={} end
cc.bazooka={}
cc.bazooka.rocket={}
-- Load & Prepare Ressources
cc.bazooka.gfx_wpn=loadgfx("weapons/launcher.bmp") -- Weapon Image
setmidhandle(cc.bazooka.gfx_wpn)
cc.bazooka.gfx_pro=loadgfx("weapons/rocket.bmp") -- Projectile Image
setmidhandle(cc.bazooka.gfx_pro)
cc.bazooka.sfx_attack=loadsfx("rocketrelease.wav") -- Attack Sound
--------------------------------------------------------------------------------
-- Weapon: Bazooka
--------------------------------------------------------------------------------
cc.bazooka.id=addweapon("cc.bazooka","Bazooka",cc.bazooka.gfx_pro) -- Add Weapon
function cc.bazooka.draw() -- Draw
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
drawinhand(cc.bazooka.gfx_wpn,6,0)
-- HUD chargebar
if weapon_charge>0 and weapon_shots==0 then
hudchargebar(weapon_charge,100)
end
-- HUD Crosshair
if weapon_shots==0 then
hudcrosshair(6,3)
end
end
function cc.bazooka.attack(attack) -- Attack
if (weapon_shots<=0) then
-- Charge
if (attack==1) then
weapon_charge=weapon_charge+1 -- Increase charge
end
-- Fire a projectile (on release/full charge)
if (attack==0 and weapon_charge>0) or (weapon_charge>=100) then
-- No more weapon switching!
useweapon(0)
playsound(cc.bazooka.sfx_attack)
weapon_shots=weapon_shots+1
id=createprojectile(cc.bazooka.rocket.id)
projectiles[id]={}
-- Ignore collision with current player at beginning
projectiles[id].ignore=playercurrent()
-- Set initial position of projectile
projectiles[id].x=getplayerx(0)+(6*getplayerdirection(0))+math.sin(math.rad(getplayerrotation(0)))*10.0
projectiles[id].y=getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*10.0
-- Initial movement
projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*20
projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*20
projectiles[id].x=projectiles[id].x-projectiles[id].sx
projectiles[id].y=projectiles[id].y-projectiles[id].sy
cc.bazooka.rocket.move(id,0)
-- Set speed of projectile
projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
-- Effects
recoil(2)
-- End Turn
endturn()
end
end
end
--------------------------------------------------------------------------------
-- Projectile: Rocket
--------------------------------------------------------------------------------
cc.bazooka.rocket.id=addprojectile("cc.bazooka.rocket") -- Add Projectile
function cc.bazooka.rocket.draw(id) -- Draw
-- Setup draw mode
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
setscale(1,1)
-- Calculate projectile rotation
setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
-- Draw projectile
drawimage(cc.bazooka.gfx_pro,projectiles[id].x,projectiles[id].y)
-- Draw Arrow if out of Screen
outofscreenarrow(projectiles[id].x,projectiles[id].y)
end
function cc.bazooka.rocket.update(id) -- Update
-- Move
cc.bazooka.rocket.move(id,1)
end
function cc.bazooka.rocket.move(id,fx)
rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
-- Particle Tail
if (fx==1) then
particle(p_smoke,projectiles[id].x-math.sin(math.rad(rot))*7,projectiles[id].y+math.cos(math.rad(rot))*7)
particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
particlefadealpha(0.01)
particle(p_lightpuff,projectiles[id].x-math.sin(math.rad(rot))*6,projectiles[id].y+math.cos(math.rad(rot))*6)
particlefadealpha(0.04)
end
-- Wind + Gravity influence on speed
projectiles[id].sx=projectiles[id].sx+getwind()
projectiles[id].sy=projectiles[id].sy+getgravity()
-- Move (in substep loop for optimal collision precision)
msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
msubx=projectiles[id].sx/msubt
msuby=projectiles[id].sy/msubt
for i=1,msubt,1 do
projectiles[id].x=projectiles[id].x+msubx
projectiles[id].y=projectiles[id].y+msuby
-- Collision
if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*3,projectiles[id].y-math.cos(math.rad(rot))*3)==1 then
if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
-- Cause damage
arealdamage(projectiles[id].x,projectiles[id].y,100,45)
-- Destroy terrain
terrainexplosion(projectiles[id].x,projectiles[id].y,25,1)
-- Crater
grey=math.random(0,40)
if math.random(0,1)==1 then
terrainalphaimage(gfx_crater100,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
else
terrainalphaimage(gfx_crater125,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
end
-- Free projectile
freeprojectile(id)
return 1
end
else
projectiles[id].ignore=0
end
-- Water
if (projectiles[id].y)>getwatery()+5 then
-- Effects
particle(p_waterhit,projectiles[id].x,projectiles[id].y)
playsound(sfx_hitwater1)
-- Free projectile
freeprojectile(id)
return 1
end
end
-- Scroll to projectile
scroll(projectiles[id].x,projectiles[id].y)
end